package controller;

import com.fasterxml.jackson.databind.ObjectMapper;
import dao.BusinessDao;
import dao.BusinessTypeDao;
import dao.OrderdetailetDao;
import dto.FindFoodInPayDto;
import dto.IndexDto;
import model.Business;
import model.BusinessType;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

@WebServlet("/OrderListController")
public class OrderListController extends HttpServlet {
    private static final long serialVersionUID = 1L;

    /**
     * @see HttpServlet#HttpServlet()
     */
    public OrderListController() {
        super();
        // TODO Auto-generated constructor stub
    }

    /**
     * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
     */
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        // TODO Auto-generated method stub

//        BusinessDao bd = new BusinessDao();
//        BusinessTypeDao btd = new BusinessTypeDao();
//        List<Business> bs = bd.findAllBusiness();
//        List<BusinessType> bst = btd.findAllTypes();
//        for(BusinessType  t:bst){
//            System.out.println(t.getName());
//        }
//        IndexDto idto = new IndexDto(bst, bs);
        OrderdetailetDao orderdetailetDao=new OrderdetailetDao();
        orderdetailetDao.findOrderList();
        FindFoodInPayDto ffd=orderdetailetDao.findOrderList();
        PrintWriter out = response.getWriter();
        ObjectMapper om = new ObjectMapper();
        out.print(om.writeValueAsString(ffd));
    }

    /**
     * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
     */
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        // TODO Auto-generated method stub
        doGet(request, response);
    }
}
